import rds from './plugin/wxredis.js'
import queue from './plugin/itask.js'

// 会话身份过期时间
const timeout = 6000;
const conf = require('../../app.config')

// develop 开发版 | trial 体验版 | release 正式版
const accountInfo = wx.getAccountInfoSync()
// API SDK
const API = () => {
  let _api = {}

  // 根据当前微信版本选择 API 地址
  const _domain = conf.app[accountInfo.miniProgram.envVersion.toLowerCase()].api

  let _sessionKey = rds.get('_sessionKey') != null ? rds.get('_sessionKey') : '',
      _isLogin = false;

  _api.Handler = {
    Header: '/Handler/',
    // 获取服务器时间
    GetTime: function (_data) {
      let _method = 'GetTime'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },

    // 获取服务器时间
    GetTime1: function (_data) {
      let _method = 'GetTime'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },

    // 获取服务器时间
    GetTime2: function (_data) {
      let _method = 'GetTime'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    }

  }
  _api.img_upload = function (file, cb) {
    let session3rd = rds.get('session3rd');
    wx.uploadFile({
      url: _domain + '/japi/common/uploadFile',
      filePath: file,
      name: 'file',
      formData: {
        'session3rd': session3rd,
        file: file
      },
      header: {
        'Content-Type': 'multipart/form-data',
        "webToken": rds.get('_sessionKey')
      },
      success(res) {
        cb && cb(_api.isJsonString(res.data))
      }
    })
  }
  _api.isJsonString = (str) => {
    try {
      if (typeof JSON.parse(str) == "object") {
        return JSON.parse(str);
      }
    } catch (e) { }
    return str;
  }
  // ================================= 以下为内部函数 ================================= // 
  /** 请求微信 API Login 并获取 Code */
  _api.login = () => {
    return new Promise((resolve, reject) => {
      wx.login({
        success: (res) => {
          let _handler = _domain + '/japi/customer/login?JSCODE=' + res.code
          //+'&openId=oURKq5VBzynbBJP4AHOb4sBV4PLk'
          _api.request(_handler, {
            code: res.code
            // 'JSCODE': res.code,
          }, "GET").then((res) => {
            console.log(res.data.code, 'code----->')
            let data = res.data.data;
            wx.setStorageSync('logincode', res.data.code)
            // 初始化会话状态
            rds.set('_sessionKey', data.webToken, timeout);
            rds.set('_openid', data.openId, timeout);
            _sessionKey = data.webToken
            queue.concatWait();
            _isLogin = false;
            resolve(res)
          });
        },
        fail: (err) => {
          reject(err)
        },
        timeout: 10 * 1000
      });
    });
  }

  /**
   * 基础请求接口
   * @param {string} url 请求完整地址
   * @param {json} data 请求参数
   * @param {string} method 请求方式 GET/POST
   */
  _api.ajax = (url, data, method) => {
    return new Promise((resolvex, reject) => {
      function fn() {
        return new Promise((resolve) => {
          _api.requestApi(url, data, method).then((res) => {
            if (res.data && res.data.code == 401) {
              _sessionKey = '';
              if (!_isLogin) {
                _isLogin = true;
                queue.pushActive(_api.login);
              }
              queue.pushWait(fn);
              resolve(res)
            } else {
              resolve(res)
              resolvex(res)
            }
          });
        });
      }
      if (_sessionKey)
        queue.pushActive(fn);
      else {
        if (!_isLogin) {
          _isLogin = true;
          queue.pushActive(_api.login);
        }
        queue.pushWait(fn);
      }
    });
  }
  /**
   * 基础请求接口
   * @param {string} url 请求完整地址
   * @param {json} data 请求参数
   * @param {string} method 请求方式 GET/POST
   */
  _api.requestApi = function (url, data, method) {
    method = method || 'POST';
    // url += '?SessionKey=' + rds.get('_sessionKey');
    return new Promise((resolve, reject) => {
      wx.request({
        url: _domain + url,
        data: data,
        method: method,
        dataType: 'json',
        header: {
          'MiniType': 'MiniApp1',
          "webToken": rds.get('_sessionKey')
        },
        success: (res) => {
          resolve(res)
        },
        fail: (err) => {
          console.log('Url:', url, ' err:', err)
          reject(err)
        }
      });
    });
  }
  _api.toast = function (txt, icon, time) {
    if (txt) {
      wx.showToast({
        title: txt,
        icon: icon || 'none',
        duration: time || 2000
      })
    };
  }
  _api.request = function (url, data, method) {
    method = method || 'POST';
    return new Promise((resolve, reject) => {
      wx.request({
        url: url,
        data: data,
        method: method,
        header: {
          'MiniType': 'MiniApp1',
          "webToken": rds.get('_sessionKey')
        },
        dataType: 'json',
        success: (res) => {
          resolve(res)
        },
        fail: (err) => {
          console.log('Url:', url, ' err:', err)
          reject(err)
        }
      });
    });
  }

  _api.interface = {
    Header: '/japi/',
    //开屏页信息接口
    getInitPageInfo: function (_data) {
      let _method = 'home/getInitPageInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //  获取首页信息
    openinginformation: function (_data) {
      let _method = 'home/homeInit'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 获取用户信息
    getCustomerInfo: function (_data) {
      let _method = 'customer/getCustomerInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    customerInfoShare: function (_data) {
      let _method = 'customer/customerInfoShare'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 获取题目
    gettitle: function (_data) {
      let _method = 'activity/getActivityAnswer'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 提交题目
    submitActivityAnswer: function (_data) {
      let _method = 'activity/submitActivityAnswer'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 授权手机号
    authPhone: function (_data) {
      let _method = 'customer/authPhone'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //  头像名称授权
    authNameAndHead: function (_data) {
      let _method = 'customer/authNameAndHead'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //用户订阅
    userSubscribeMessage: function (_data) {
      let _method = 'common/userSubscribeMessage'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 获取答题返回记录
    getActivityAnswerLog: function (_data) {
      let _method = 'activity/getActivityAnswerLog'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 我的资料页
    getCustomerByOpenId: function (_data) {
      let _method = 'customer/getCustomerInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 获取验证码
    getRegisterCode: function (_data) {
      let _method = 'customer/getRegisterCode'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 更新我的资料
    updateCustomer: function (_data) {
      let _method = 'customer/updateCustomer'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 获取优惠券列表
    getCustomerCouponByCustomerId: function (_data) {
      let _method = 'coupon/getCustomerCouponByCustomerId'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 获取福利中心主页
    integralMallContent: function (_data) {
      let _method = 'mall/integralMallContent'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    //收货地址列表
    getCustomerAddressList: function (_data) {
      let _method = 'customer/getCustomerAddressList'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    //添加收货地址
    addCustomerAddress: function (_data) {
      let _method = 'customer/addCustomerAddress'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //删除收货地址
    deleteCustomerAddress: function (_data) {
      let _method = 'customer/deleteCustomerAddress?addressId='+_data
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    //修改收货地址
    updateCustomerAddress: function (_data) {
      let _method = 'customer/updateCustomerAddress'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //收货地址列表单个
    getCustomerAddress: function (_data) {
      let _method = 'customer/getCustomerAddress?addressId='+_data
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    //修改默认地址
    updateCustomerAddressDefault: function (_data) {
      let _method = 'customer/updateCustomerAddressDefault?addressId='+_data
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    uploadCustomerHeardImgFile:function (file, cb) {
      return _api.img_upload(file,cb);
    },
    /*
    uploadCustomerHeardImgFile:function (file, cb) {
      console.log('file1------------', file)
      wx.uploadFile({
        url: _domain + '/customer/uploadCustomerHeardImgFile',
        filePath: file,
        name: 'file',
        data: { file: file },
        formData: { file: file },
        header: {
          'MiniType': 'MiniApp1',
          'Content-Type': 'multipart/form-data',
          "webToken": rds.get('_sessionKey')
        },
        success(res) {
          cb && cb(_api.isJsonString(res.data))
        }
      })
    },

     */
    // 获取活力值详情
    integralDetails: function (_data) {
      let _method = 'mall/integralDetails'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 获取礼品详情
    integralMallGetDetail: function (_data) {
      let _method = 'mall/integralMallGetDetail'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 中奖记录
    prizerecord: function (_data) {
      let _method = 'drawSort/win-prize-record'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 福利中心添加收藏
    integralcollection: function (_data) {
      let _method = 'mall/collect/add'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 福利中心取消收藏
    integralcollectiondel: function (_data) {
      let _method = 'mall/collect/del'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 福利中心礼品兑换
    integralexchange: function (_data) {
      let _method = 'mall/integral-exchange'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 福利中心兑礼明细
    integralExchangeDetails: function (_data) {
      let _method = 'mall/integralExchangeDetails'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 福利中心查看券码
    details: function (_data) {
      let _method = 'mall/hema/details'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 福利中心 获取抽奖次数及活力值信息
    drawdetail: function (_data) {
      let _method = 'drawSort/draw-detail'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 福利中心 抽奖
    drawexchange: function (_data) {
      let _method = 'drawSort/draw-exchange'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 福利中心实物领取
    receive: function (_data) {
      let _method = 'drawSort/receive'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 获取首页最新活动
    getNewest: function (_data) {
      let _method = 'home/getNewest'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 获取健康里程产品列表
    HealthmileageList: function (_data) {
      let _method = '/mileage/index'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 获取健康里程兑换权益
    getproductexchangeequity: function (_data) {
      let _method = 'mileage/get-product-exchange-equity'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 健康里程自己兑换
    getproductexchange: function (_data) {
      let _method = 'mileage/get-product-exchange'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 健康里程兑换记录
    getproductexchangerecords: function (_data) {
      let _method = 'mileage/get-product-exchange-records'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 获取健康里程产品详情
    getproductdetails: function (_data) {
      let _method = 'mileage/get-product-details'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 健康里程转赠好友
    getproductgive: function (_data) {
      let _method = 'mileage/get-product-give'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 健康扫码接口
    healthyScanPoint: function (_data) {
      let _method = 'scan/healthyScanPoint'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 普通扫码接口
    smallScanPoint: function (_data) {
      let _method = 'scan/smallScanPoint'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 获取免费试用产品列表
    getTrialProduct: function (_data) {
      let _method = 'trial/getTrialProduct'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 免费试用立即申请
    getTrial: function (_data) {
      let _method = 'trial/getTrial'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 免费试用  根据会员Id查询试用权益
    getTrialRedemptionByCustomerId: function (_data) {
      let _method = 'trialRedemption/getTrialRedemptionByCustomerId'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 免费试用  根据试用产品Id查询试用产品详细信息
    getTrialRedemption: function (_data) {
      let _method = 'trialRedemption/getTrialRedemption'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 免费试用  新增试用记录
    insertTrial: function (_data) {
      let _method = 'trial/insertTrial'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 免费试用 获取个人试用记录
    queryTrial: function (_data) {
      let _method = 'trial/queryTrial'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 免费试用 查询物流轨迹信息
    getLogisticInfo: function (_data) {
      let _method = 'trial/getLogisticInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 打卡 签到初始化
    signInInit: function (_data) {
      let _method = 'signIn/signInInit'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 打卡 激活签到
    activateSignIn: function (_data) {
      let _method = 'signIn/activateSignIn'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 打卡 用户签到
    userSignIn: function (_data) {
      let _method = 'signIn/userSignIn'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 入手信息
    getRushouInfo: function (_data) {
      let _method = 'rushou/getRushouInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 兑换入手优惠券
    exchangeCoupon: function (_data) {
      let _method = 'rushou/exchangeCoupon'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 好物信息
    getHaowuInfo: function (_data) {
      let _method = 'haowu/getHaowuInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 好物列表
    getHaowuList: function (_data) {
      let _method = 'haowu/getHaowuList'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 好物tab信息 
    getHaowuTabInfo: function (_data) {
      let _method = 'haowu/getHaowuTabInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 扫码记录
    scanLog: function (_data) {
      let _method = 'scan/scanLog'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 获取我的消息记录
    getMotByCustomerId: function (_data) {
      let _method = 'smot/getMotByCustomerId'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 我的消息设为已读
    updateMotRead: function (_data) {
      let _method = 'mot/updateMotRead'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 活力圈首页
    getVitalityHome: function (_data) {
      let _method = 'vitality/getVitalityHome'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 活力圈列表
    getVitalityList: function (_data) {
      let _method = 'vitality/getVitalityList'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 活力圈详情
    getVitalityInfo: function (_data) {
      let _method = 'vitality/getVitalityInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 活力圈我的评论列表
    getVitalityComments: function (_data) {
      let _method = 'vitality/getVitalityComments'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 点赞活力圈
    praiseVitality: function (_data) {
      let _method = 'vitality/praiseVitality'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 活力圈 生成小程序二维码返回路径
    qrcode: function (_data) {
      let _method = 'common/qrcode'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 评论活力圈
    commentsVitality: function (_data) {
      let _method = 'vitality/commentsVitality'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 用户勋章情况
    userVitalityTask: function (_data) {
      let _method = 'vitality/userVitalityTask'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 活力圈转发
    transpondVitality: function (_data) {
      let _method = 'vitality/transpondVitality'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 活力圈我的信息
    getVitalityMy: function (_data) {
      let _method = 'vitality/getVitalityMy'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 活力圈我的发帖
    myNews: function (_data) {
      let _method = 'vitality/myNews'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 活力圈我的点赞
    myPraise: function (_data) {
      let _method = 'vitality/myPraise'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 我的评论
    myComments: function (_data) {
      let _method = 'vitality/myComments'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 活力圈删除
    delUserNews: function (_data) {
      let _method = 'vitality/delUserNews'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 活力圈发帖 标签
    getTabByType: function (_data) {
      let _method = 'tab/getTabByType'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 活力圈发帖
    pushNews: function (_data) {
      let _method = 'vitality/pushNews'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 用户弹窗
    getPopupInfo: function (_data) {
      let _method = 'common/getPopupInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 用户弹窗
    getRushouList: function (_data) {
      let _method = 'rushou/getRushouList'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },

    // 标签操作 新监测
    tagOperation: function (_data) {
      let _method = 'tag/tagOperation'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },

    // 盲盒排行榜列表和自己的排名列表
    getYearRankingList: function (_data) {
      let _method = 'year/getYearRankingList'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 盲盒排行榜列表和自己的排名列表
    takeYearGift: function (_data) {
      let _method = 'year/takeYearGift'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 用户排行榜奖品
    userYearRankingGiftList: function (_data) {
      let _method = 'year/userYearRankingGiftList'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 用户排行榜奖品
    addGiftUserInfo: function (_data) {
      let _method = 'year/addGiftUserInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // referral 计划接口
    // 查看盒马卡号卡密
    GetHeMaPrizeInfo: function (_data) {
      let _method = 'referral/GetHeMaPrizeInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 查看邀请者信息
    GetInviteInfo: function (_data) {
      let _method = 'referral/GetInviteInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 好友助力列表
    GetInviteList: function (_data) {
      let _method = 'referral/GetInviteList'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 查看中奖信息列表
    GetLuckyRecord: function (_data) {
      let _method = 'referral/GetLuckyRecord'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 邀请成功下单列表
    GetShareOrderList: function (_data) {
      let _method = 'referral/GetShareOrderList'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 抽奖
    Lucky: function (_data) {
      let _method = 'referral/Lucky'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
      0
    },
    // referral初始化
    ReferralInit: function (_data) {
      let _method = 'referral/ReferralInit'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 鼠标垫实物留资
    SetRecord: function (_data) {
      let _method = 'referral/SetRecord'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 邀请下单邀请码
    ShareOrder: function (_data) {
      let _method = 'referral/ShareOrder'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 邀请下单邀请码
    Invite: function (_data) {
      let _method = 'referral/Invite'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 领取任务奖励
    receivetaskreward: function (_data) {
      let _method = 'task/receivetaskreward'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    // 获取任务记录
    gettasklist: function (_data) {
      let _method = 'task/gettasklist'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // 查看好友试用订单详情
    getfriendontrialorder: function (_data) {
      let _method = 'mall/getfriendontrialorder'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
    // （邀请新人 的优惠券奖励），获取拉新优惠券信息
    gethelpcouponinfo: function (_data) {
      let _method = 'customer/gethelpcouponinfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "GET");
    },
  }

  //虎年年终红包活动接口－－－桃子20220111--start
  _api.redYear = {
    Header: '/japi/redYear/',
    //获取基本信息
    getBasicInfo: function (_data) {
      let _method = 'getBasicInfo'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //福袋跳转记录
    redYearClickLuckBag: function (_data) {
      let _method = 'redYearClickLuckBag'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //年终红包活动好友助力列表
    redYearFriendHelpList: function (_data) {
      let _method = 'redYearFriendHelpList'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //年终红包活动助力
    redYearHelp: function (_data) {
      let _method = 'redYearHelp'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //年终红包抽奖
    redYearLottery: function (_data) {
      let _method = 'redYearLottery'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //年终红包生成海报
    redYearPoster: function (_data) {
      let _method = 'redYearPoster'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //年终红包活动用户奖品列表
    redYearUserGiftList: function (_data) {
      let _method = 'redYearUserGiftList'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //年终红包用户海报页
    redYearUserPoster: function (_data) {
      let _method = 'redYearUserPoster'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //音频check
    voiceCheck: function (_data) {
      let _method = 'voiceCheck'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //是否在活动内
    isActivityTime: function (_data) {
      let _method = 'isActivityTime'
      _data = _data || {};
      return _api.ajax(this.Header + _method, _data, "POST");
    },
    //音频上传
    // voiceUpload: function (_data) {
    //     let _method = 'voiceUpload'
    //     _data = _data || {};
    //     return _api.ajax(this.Header + _method, _data, "POST");
    // },
  }
  //虎年年终红包活动接口－－－桃子20220111--end
  // 用户上传音频 start
  _api.SetVoiceUrl = function (file, cb) {
    console.log('file1------------', file)
    wx.uploadFile({
      url: _domain + '/japi/redYear/voiceUpload',
      filePath: file,
      name: 'file',
      data: { file: file },
      formData: { file: file },
      header: {
        'MiniType': 'MiniApp1',
        'Content-Type': 'multipart/form-data',
        "webToken": rds.get('_sessionKey')
      },
      success(res) {
        cb && cb(_api.isJsonString(res.data))
      }
    })
  }
  // 用户上传音频 end



  return _api;
}
module.exports = API();